clear all

use COMBINED_waves_1234.dta, replace

***Recode states in order***
rename inputstate state
sort state
recode state (4=3) (5=4) (6=5) (8=6) (9=7) (10=8) (11=9) (12=10) (13=11) (15=12) (16=13) (17=14) (18=15) (19=16) (20=17) (21=18) (22=19) (23=20) (24=21) (25=22) (26=23) (27=24) (28=25) (29=26) (30=27) (31=28) (32=29) (33=30) (34=31) (35=32) (36=33) (37=34) (38=35) (39=36) (40=37) (41=38) (42=39) (44=40) (45=41) (46=42) (47=43) (48=44) (49=45) (50=46) (51=47) (53=48) (54=49) (55=50) (56=51)

***Label states**
label define statelabels 1 "Alabama" 2 "Alaska" 3 "Arizona" 4 "Arkansas" 5 "California" 6 "Colorado" 7 "Connecticut" 8 "Delaware" 9 "District of Columbia" 10 "Florida" 11 "Georgia" 12 "Hawaii" 13 "Idaho" 14 "Illinois" 15 "Indiana" 16 "Iowa" 17 "Kansas" 18 "Kentucky" 19 "Louisiana" 20 "Maine" 21 "Maryland" 22 "Massachusetts" 23 "Michigan" 24 "Minnesota" 25 "Mississippi" 26 "Missouri" 27 "Montana" 28 "Nebraska" 29 "Nevada" 30 "New Hampshire" 31 "New Jersey" 32 "New Mexico" 33 "New York" 34 "North Carolina" 35 "North Dakota" 36 "Ohio" 37 "Oklahoma" 38 "Oregon" 39 "Pennsylvania" 40 "Rhode Island" 41 "South Carolina" 42 "South Dakota" 43 "Tennessee" 44 "Texas" 45 "Utah" 46 "Vermont" 47 "Virginia" 48 "Washington" 49 "West Virginia" 50 "Wisconsin" 51 "Wyoming"
label values state statelabels


***Create string utility variable***
gen utility_type=.
replace utility_type=1 if OwnershipType=="Municipal"
replace utility_type=2 if OwnershipType=="Investor Owned"
replace utility_type=3 if OwnershipType=="Cooperative"
replace utility_type=4 if OwnershipType=="Special District"
replace utility_type=5 if OwnershipType=="Federal"
label define utilitylabel 1 "Municipal" 2 "IOU" 3 "Coop" 4 "Special District" 5 "Federal"
label values utility_type utilitylabel

gen muni = (utility_type==1)
gen iou = (utility_type==2)
gen coop = (utility_type==3)
gen sd = (utility_type==4)
gen federal = (utility_type==5)

save energy_insecurity_combined_waves1234_may.dta, replace

use energy_insecurity_combined_waves1234_may.dta, replace


***Import Disconnections Spreadsheet****
import delimited "disconnections_spreadsheet_waves.csv", numericcols(1) clear
*rename ïstate state


save "disconnection_policies_wave.dta", replace


use energy_insecurity_combined_waves1234_may.dta, replace
save energy_insecurity_combined_waves1234_Pmay.dta, replace

***Merge survey data with disconnections data****
use disconnection_policies_wave.dta, clear
sort state
merge 1:m state using energy_insecurity_combined_waves1234_Pmay.dta, nogenerate
sort state

***Label states**
label define state_labels 1 "Alabama" 2 "Alaska" 3 "Arizona" 4 "Arkansas" 5 "California" 6 "Colorado" 7 "Connecticut" 8 "Delaware" 9 "District of Columbia" 10 "Florida" 11 "Georgia" 12 "Hawaii" 13 "Idaho" 14 "Illinois" 15 "Indiana" 16 "Iowa" 17 "Kansas" 18 "Kentucky" 19 "Louisiana" 20 "Maine" 21 "Maryland" 22 "Massachusetts" 23 "Michigan" 24 "Minnesota" 25 "Mississippi" 26 "Missouri" 27 "Montana" 28 "Nebraska" 29 "Nevada" 30 "New Hampshire" 31 "New Jersey" 32 "New Mexico" 33 "New York" 34 "North Carolina" 35 "North Dakota" 36 "Ohio" 37 "Oklahoma" 38 "Oregon" 39 "Pennsylvania" 40 "Rhode Island" 41 "South Carolina" 42 "South Dakota" 43 "Tennessee" 44 "Texas" 45 "Utah" 46 "Vermont" 47 "Virginia" 48 "Washington" 49 "West Virginia" 50 "Wisconsin" 51 "Wyoming"
label values state state_labels






save ei_survey_policy_waves.dta, replace

****Merge additional zip-code matched respondents***
use missing2, replace
gen utility_type=.
replace utility_type=1 if muni==1
replace utility_type=2 if iou==1
replace utility_type=3 if coop==1
label define utilitylabel 1 "Municipal" 2 "IOU" 3 "Coop" 4 "Special District" 5 "Federal"
label values utility_type utilitylabel

merge 1:m caseid_w1 using ei_survey_policy_waves, nogenerate

save ei_survey_policy_waves.dta, replace




****Collapse dataset into variable of interest for each month, rename variables into common names, and append****
******Wave 1 Data******
use ei_survey_policy_waves.dta, replace
keep weight4 weight1 caseid_National caseid_Indiana caseid_w1 inputzip1 marstat state utility utility_type muni iou coop iou_cov coop_cov muni_cov sd_cov fed_cov moratorium_wave1 moratorium_wave1_days voluntary_wave1 voluntary_wave1_days disconnect_may caseid_National hhsize1 employ1 gender black hispanic educ1 unemployed1 marstat inputzip1 hh_under51 hh_over651 hh_disability1 covid_foregoexpenses1 hhbill_may notice_may age energy_assistance_may gov_assistance_may income1 under_100_fpl1 electronic_device1 covid_stimulus_yr wap_may liheap_may snap_may tanf_may ssi_may medicaid_may vet_benefits_may unemp_insurance_may gov_agency_may energy_provider_may friend_family_may faith_org_may nonprofit_may payday_lender_may bankloan_may ownhome1 fuel_payment1 hhbill_year notice_year disconnect_year dwelling_type1

drop if hhbill_may==.

gen wave=1

rename weight4 weight_balanced
rename weight1 weight
rename inputzip1 inputzip
rename hhsize1 hhsize
rename employ1 employ
rename educ1 educ
rename unemployed1 unemployed
rename hh_under51 hh_under5
rename hh_over651 hh_over65
rename hh_disability1 hh_disability
rename income1 income
rename under_100_fpl1 under_100_fpl
rename moratorium_wave1 moratorium
rename moratorium_wave1_days moratorium_days
rename voluntary_wave1 voluntary
rename voluntary_wave1_days voluntary_days
rename disconnect_may disconnected
rename covid_foregoexpenses1 forego_expenses
rename hhbill_may hhbill
rename notice_may notice
rename energy_assistance_may energy_assistance
rename gov_assistance_may gov_assistance
rename electronic_device1 device
rename covid_stimulus_yr stimulus
rename wap_may wap
rename liheap_may liheap
rename snap_may snap
rename tanf_may tanf
rename ssi_may ssi
rename medicaid_may medicaid
rename vet_benefits_may vet_benefits
rename unemp_insurance_may unemp_insurance
rename gov_agency_may gov_agency
rename energy_provider_may energy_provider
rename friend_family_may friend_family
rename faith_org_may faith_org
rename nonprofit_may nonprofit
rename payday_lender_may payday_lender
rename bankloan_may bankloan
rename ownhome1 ownhome
rename fuel_payment1 fuel_payment
rename dwelling_type1 dwelling_type

gen covered_moratorium=0
replace covered_moratorium=1 if moratorium==1 & utility_type==1 & muni_cov==1 
replace covered_moratorium=1 if moratorium==1 & utility_type==2 & iou_cov==1
replace covered_moratorium=1 if moratorium==1 & utility_type==3 & coop_cov==1
replace covered_moratorium=1 if moratorium==1 & utility_type==4 & sd_cov==1
replace covered_moratorium=1 if moratorium==1 & utility_type==5 & fed_cov==1


gen covered_voluntary=0
replace covered_voluntary=1 if voluntary==1 & utility_type==1 & muni_cov==1 
replace covered_voluntary=1 if voluntary==1 & utility_type==2 & iou_cov==1
replace covered_voluntary=1 if voluntary==1 & utility_type==3 & coop_cov==1
replace covered_voluntary=1 if voluntary==1 & utility_type==4 & sd_cov==1
replace covered_voluntary=1 if voluntary==1 & utility_type==5 & fed_cov==1



gen dayscovered_moratorium=0
replace dayscovered_moratorium = moratorium_days if covered_moratorium==1

gen dayscovered_voluntary=0
replace dayscovered_voluntary = voluntary_days if covered_voluntary==1

gen dayscovered_total=0
replace dayscovered_total = dayscovered_moratorium + dayscovered_voluntary

save wave1_policy.dta, replace


*******Wave 2 Data********
use ei_survey_policy_waves.dta, replace
keep weight4 weight2 caseid_National caseid_Indiana caseid_w1 inputzip2 marstat state utility utility_type muni iou coop iou_cov coop_cov muni_cov sd_cov fed_cov moratorium_wave2 moratorium_wave2_days voluntary_wave2 voluntary_wave2_days disconnect_3months2 forego_expenses_3mos2 hhbill_3months2 notice_3months2 energy_assistance_3mos2 gov_assistance_3months2 wap_3mos2 liheap_3mos2 snap_3mos2 tanf_3mos2 tanf_3mos2 ssi_3mos2 medicaid_3mos2 vet_benefits_3mos2 unemp_insurance_3mos2 gov_agency_3mos2 energy_provider_3mos2 friend_family_3mos2 faith_org_3mos2 nonprofit_3mos2 payday_lender_3mos2 bankloan_3mos2 caseid_National hhsize2 employ2 gender black hispanic educ2 unemployed2 income2 under_100_fpl2 electronic_device2 covid_stimulus2 marstat inputzip2 hh_under52 hh_over652 hh_disability2 age ownhome2 fuel_payment2 utility_debt2 dwelling_type2

drop if hhbill_3months2==.

gen wave=2

rename weight4 weight_balanced
rename weight2 weight
rename inputzip2 inputzip
rename hhsize2 hhsize
rename employ2 employ
rename educ2 educ
rename unemployed2 unemployed
rename hh_under52 hh_under5
rename hh_over652 hh_over65
rename hh_disability2 hh_disability
rename income2 income
gen under_100_fpl=0
replace under_100_fpl=1 if under_100_fpl2==1
rename moratorium_wave2 moratorium
rename moratorium_wave2_days moratorium_days
rename voluntary_wave2 voluntary
rename voluntary_wave2_days voluntary_days
rename disconnect_3months2 disconnected
rename forego_expenses_3mos2 forego_expenses
rename hhbill_3months2 hhbill
rename notice_3months2 notice
rename energy_assistance_3mos2 energy_assistance
rename gov_assistance_3months2 gov_assistance
rename electronic_device2 device
rename covid_stimulus2 stimulus
rename wap_3mos2 wap
rename liheap_3mos2 liheap
rename snap_3mos2 snap
rename tanf_3mos2 tanf
rename ssi_3mos2 ssi
rename medicaid_3mos2 medicaid
rename vet_benefits_3mos2 vet_benefits
rename unemp_insurance_3mos2 unemp_insurance
rename gov_agency_3mos2 gov_agency
rename energy_provider_3mos2 energy_provider
rename friend_family_3mos2 friend_family
rename faith_org_3mos2 faith_org
rename nonprofit_3mos2 nonprofit
rename payday_lender_3mos2 payday_lender
rename bankloan_3mos2 bankloan
rename ownhome2 ownhome
rename fuel_payment2 fuel_payment
rename utility_debt2 utility_debt
rename dwelling_type2 dwelling_type


gen covered_moratorium=0
replace covered_moratorium=1 if moratorium==1 & utility_type==1 & muni_cov==1 
replace covered_moratorium=1 if moratorium==1 & utility_type==2 & iou_cov==1
replace covered_moratorium=1 if moratorium==1 & utility_type==3 & coop_cov==1
replace covered_moratorium=1 if moratorium==1 & utility_type==4 & sd_cov==1
replace covered_moratorium=1 if moratorium==1 & utility_type==5 & fed_cov==1


gen covered_voluntary=0
replace covered_voluntary=1 if voluntary==1 & utility_type==1 & muni_cov==1 
replace covered_voluntary=1 if voluntary==1 & utility_type==2 & iou_cov==1
replace covered_voluntary=1 if voluntary==1 & utility_type==3 & coop_cov==1
replace covered_voluntary=1 if voluntary==1 & utility_type==4 & sd_cov==1
replace covered_voluntary=1 if voluntary==1 & utility_type==5 & fed_cov==1



gen dayscovered_moratorium=0
replace dayscovered_moratorium = moratorium_days if covered_moratorium==1

gen dayscovered_voluntary=0
replace dayscovered_voluntary = voluntary_days if covered_voluntary==1

gen dayscovered_total=0
replace dayscovered_total = dayscovered_moratorium + dayscovered_voluntary


save wave2_policy.dta, replace




*******Wave 3 Data********
use ei_survey_policy_waves.dta, replace
keep weight4 weight3 caseid_National caseid_Indiana caseid_w1 inputzip3 marstat state utility utility_type muni iou coop iou_cov coop_cov muni_cov sd_cov fed_cov moratorium_wave3 moratorium_wave3_days voluntary_wave3 voluntary_wave3_days disconnect_5months forego_expenses_5mos hhbill_5months notice_5months energy_assistance_5mos gov_assistance_5months wap_5mos liheap_5mos snap_5mos tanf_5mos tanf_5mos ssi_5mos medicaid_5mos vet_benefits_5mos unemp_insurance_5mos gov_agency_5mos energy_provider_5mos friend_family_5mos faith_org_5mos nonprofit_5mos payday_lender_5mos bankloan_5mos caseid_National hhsize3 employ3 gender black hispanic educ3 unemployed3 income3 under_100_fpl3 electronic_device3 stimulus_5mos marstat inputzip3 hh_under53 hh_over653 hh_disability3 age ownhome3 fuel_payment3 utility_debt3 dwelling_type3

drop if hhbill_5months==.

gen wave=3

rename weight4 weight_balanced
rename weight3 weight
rename inputzip3 inputzip
rename hhsize3 hhsize
rename employ3 employ
rename educ3 educ
rename unemployed3 unemployed
rename hh_under53 hh_under5
rename hh_over653 hh_over65
rename hh_disability3 hh_disability
rename income3 income
gen under_100_fpl=0
replace under_100_fpl=1 if under_100_fpl3==1
rename moratorium_wave3 moratorium
rename moratorium_wave3_days moratorium_days
rename voluntary_wave3 voluntary
rename voluntary_wave3_days voluntary_days
rename disconnect_5months disconnected
rename forego_expenses_5mos forego_expenses
rename hhbill_5months hhbill
rename notice_5months notice
rename energy_assistance_5mos energy_assistance
rename gov_assistance_5months gov_assistance
rename electronic_device3 device
rename stimulus_5mos stimulus
rename wap_5mos wap
rename liheap_5mos liheap
rename snap_5mos snap
rename tanf_5mos tanf
rename ssi_5mos ssi
rename medicaid_5mos medicaid
rename vet_benefits_5mos vet_benefits
rename unemp_insurance_5mos unemp_insurance
rename gov_agency_5mos gov_agency
rename energy_provider_5mos energy_provider
rename friend_family_5mos friend_family
rename faith_org_5mos faith_org
rename nonprofit_5mos nonprofit
rename payday_lender_5mos payday_lender
rename bankloan_5mos bankloan
rename ownhome3 ownhome
rename fuel_payment3 fuel_payment
rename utility_debt3 utility_debt
rename dwelling_type3 dwelling_type


gen covered_moratorium=0
replace covered_moratorium=1 if moratorium==1 & utility_type==1 & muni_cov==1 
replace covered_moratorium=1 if moratorium==1 & utility_type==2 & iou_cov==1
replace covered_moratorium=1 if moratorium==1 & utility_type==3 & coop_cov==1
replace covered_moratorium=1 if moratorium==1 & utility_type==4 & sd_cov==1
replace covered_moratorium=1 if moratorium==1 & utility_type==5 & fed_cov==1


gen covered_voluntary=0
replace covered_voluntary=1 if voluntary==1 & utility_type==1 & muni_cov==1 
replace covered_voluntary=1 if voluntary==1 & utility_type==2 & iou_cov==1
replace covered_voluntary=1 if voluntary==1 & utility_type==3 & coop_cov==1
replace covered_voluntary=1 if voluntary==1 & utility_type==4 & sd_cov==1
replace covered_voluntary=1 if voluntary==1 & utility_type==5 & fed_cov==1



gen dayscovered_moratorium=0
replace dayscovered_moratorium = moratorium_days if covered_moratorium==1

gen dayscovered_voluntary=0
replace dayscovered_voluntary = voluntary_days if covered_voluntary==1

gen dayscovered_total=0
replace dayscovered_total = dayscovered_moratorium + dayscovered_voluntary

save wave3_policy.dta, replace




*******Wave 4 Data********
use ei_survey_policy_waves.dta, replace
keep weight4 caseid_National caseid_Indiana caseid_w1 inputzip4 marstat state utility utility_type muni iou coop iou_cov coop_cov muni_cov sd_cov fed_cov moratorium_wave4 moratorium_wave4_days voluntary_wave4 voluntary_wave4_days disconnect_4months forego_expenses_4mos hhbill_4months notice_4months energy_assistance_4mos gov_assistance_4months wap_4mos liheap_4mos snap_4mos tanf_4mos tanf_4mos ssi_4mos medicaid_4mos vet_benefits_4mos unemp_insurance_4mos gov_agency_4mos energy_provider_4mos friend_family_4mos faith_org_4mos nonprofit_4mos payday_lender_4mos bankloan_4mos caseid_National hhsize4 employ4 gender black hispanic educ4 unemployed4 income4 under_100_fpl4 electronic_device4 stimulus_4mos marstat inputzip4 hh_under54 hh_over654 hh_disability4 age ownhome4 fuel_payment4 utility_debt4 dwelling_type4

drop if hhbill_4months==.

gen wave=4

clonevar weight_balanced = weight4
rename weight4 weight
rename inputzip4 inputzip
rename hhsize4 hhsize
rename employ4 employ
rename educ4 educ
rename unemployed4 unemployed
rename hh_under54 hh_under5
rename hh_over654 hh_over65
rename hh_disability4 hh_disability
rename income4 income
gen under_100_fpl=0
replace under_100_fpl=1 if under_100_fpl4==1
rename moratorium_wave4 moratorium
rename moratorium_wave4_days moratorium_days
rename voluntary_wave4 voluntary
rename voluntary_wave4_days voluntary_days
rename disconnect_4months disconnected
rename forego_expenses_4mos forego_expenses
rename hhbill_4months hhbill
rename notice_4months notice
rename energy_assistance_4mos energy_assistance
rename gov_assistance_4months gov_assistance
rename electronic_device4 device
rename stimulus_4mos stimulus
rename wap_4mos wap
rename liheap_4mos liheap
rename snap_4mos snap
rename tanf_4mos tanf
rename ssi_4mos ssi
rename medicaid_4mos medicaid
rename vet_benefits_4mos vet_benefits
rename unemp_insurance_4mos unemp_insurance
rename gov_agency_4mos gov_agency
rename energy_provider_4mos energy_provider
rename friend_family_4mos friend_family
rename faith_org_4mos faith_org
rename nonprofit_4mos nonprofit
rename payday_lender_4mos payday_lender
rename bankloan_4mos bankloan
rename ownhome4 ownhome
rename fuel_payment4 fuel_payment
rename utility_debt4 utility_debt
rename dwelling_type4 dwelling_type


gen covered_moratorium=0
replace covered_moratorium=1 if moratorium==1 & utility_type==1 & muni_cov==1 
replace covered_moratorium=1 if moratorium==1 & utility_type==2 & iou_cov==1
replace covered_moratorium=1 if moratorium==1 & utility_type==3 & coop_cov==1
replace covered_moratorium=1 if moratorium==1 & utility_type==4 & sd_cov==1
replace covered_moratorium=1 if moratorium==1 & utility_type==5 & fed_cov==1


gen covered_voluntary=0
replace covered_voluntary=1 if voluntary==1 & utility_type==1 & muni_cov==1 
replace covered_voluntary=1 if voluntary==1 & utility_type==2 & iou_cov==1
replace covered_voluntary=1 if voluntary==1 & utility_type==3 & coop_cov==1
replace covered_voluntary=1 if voluntary==1 & utility_type==4 & sd_cov==1
replace covered_voluntary=1 if voluntary==1 & utility_type==5 & fed_cov==1


gen dayscovered_moratorium=0
replace dayscovered_moratorium = moratorium_days if covered_moratorium==1

gen dayscovered_voluntary=0
replace dayscovered_voluntary = voluntary_days if covered_voluntary==1

gen dayscovered_total=0
replace dayscovered_total = dayscovered_moratorium + dayscovered_voluntary

save wave4_policy.dta, replace





***Append datasets***
clear all

use wave1_policy.dta, clear
append using wave2_policy.dta
append using wave3_policy.dta
append using wave4_policy.dta


**generate variables for energy insecurity in the previous 12 months (May 2019-May 2020)
rename hhbill_year hhbill_previousyear
rename notice_year notice_previousyear
label define notice_yrlabel 1 "1" 2 "2" 3 "3" 4 "4" 5 "5" 6 "6" 7 "7" 8 "8" 9 "9" 10 "10" 11 "11"
label values notice_previousyear notice_yrlabel
rename disconnect_year disconnect_previousyear
label define disconnect_yrlabel 1 "1" 2 "2" 3 "3" 4 "4" 5 "5" 6 "6" 7 "7" 8 "8" 9 "9" 10 "10" 11 "11"
label values disconnect_previousyear disconnect_yrlabel

save waves_policy_combined.dta, replace
use waves_policy_combined.dta, replace
